package com.hl.web.fore;

import com.hl.pojo.PsychologicalAssessment;
import com.hl.service.PsychologicalAssessmentService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/psychologicalAssessment")
public class PsychologicalAssessmentController {
    @Autowired
    private PsychologicalAssessmentService service;

    @GetMapping("/sosuo")
    public ResultEntity sosuo(String name){
        List<PsychologicalAssessment> lis = service.findAll();
        for(int i=0;i<lis.size();i++){
            if(!lis.get(i).getAssessmentName().contains(name)){
                lis.remove(i);
                i--;
            }
        }
        return ResultEntity.ok(lis);
    }

    @PostMapping("/add")
    public ResultEntity add(@RequestBody PsychologicalAssessment psychologicalAssessment) {
        service.add(psychologicalAssessment);
        return ResultEntity.ok();
    }


    @GetMapping("/findAll")
    public ResultEntity findAll() {
        return ResultEntity.ok(service.findAll());
    }


    @GetMapping("/del")
    public ResultEntity del(Integer id) {
        service.del(id);
        return ResultEntity.ok();
    }


    @GetMapping("/findById")
    public ResultEntity findById(Integer id) {
        return ResultEntity.ok(service.findById(id));
    }

    @PostMapping("/update")
    public ResultEntity update(@RequestBody PsychologicalAssessment psychologicalAssessment) {
        service.update(psychologicalAssessment);
        return ResultEntity.ok();
    }

}
